package com.view.loadmore

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.utils.SizeUtils
import com.view.R
import kotlinx.android.synthetic.main.layout_loadmore.view.*

/**
 * @describe:
 * @Author: lixiaopeng
 * @Date: 2020/7/10
 */
class LoadMoreView : LinearLayout,ILoadMore {

    private val TAG = "LoadMoreView"

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {

        orientation = HORIZONTAL
        gravity = Gravity.CENTER
        val inflate = View.inflate(context, R.layout.layout_loadmore, this)
        layoutParams = ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, SizeUtils.dip2px(context, 60))
        inflate.layoutParams = layoutParams
    }

    override fun complete(completeText: String) {
        loadmoreTitle.text = completeText
        loadmore.visibility = View.GONE
        visibility = View.VISIBLE
    }

    override fun clickLoad(clickLoadText: String) {
        loadmoreTitle.text = clickLoadText
        loadmore.visibility = View.GONE
        visibility = View.VISIBLE
    }

    override fun fail(failText: String) {
        loadmoreTitle.text = failText
        loadmore.visibility = View.GONE
        visibility = View.VISIBLE
    }

    override fun loading(loadingText: String) {
        loadmoreTitle.text = loadingText
        loadmore.visibility = View.VISIBLE
        visibility = View.VISIBLE
    }

    override fun non() {
        loadmoreTitle.text = ""
        loadmore.visibility = View.GONE
        visibility = View.GONE
    }
}